import Router from 'vue-router'

/**
 * 解码
 */
function decode (str) {
  try {
    return decodeURIComponent(str)
  } catch (err) {
    console.error("Error decoding \"" + str + "\". Leaving it intact.");
  }
  return str
}

/**
 * 解决中文标签跳转报错问题
 */
const VueRouterMatch = Router.prototype.match
Router.prototype.match = function match (raw, currentRoute, redirectedFrom) {
  if (typeof raw === 'string') {
    raw = decode(raw)
  }
  return VueRouterMatch.call(this, raw, currentRoute, redirectedFrom)
}

export default ({ router }) => {
  
  /**
   * 路由切换事件处理
   */
  // router.beforeEach((to, from, next) => {
  //   var fullPath = decode(to.fullPath)
  //   // console.log("切换路由", fullPath, decode(from.fullPath));

  //   /*
  //   百度统计配置——触发百度的pv统计
  //   */
  //   if (typeof _hmt != "undefined") {
  //     if (to.path) {
  //       _hmt.push(["_trackPageview", fullPath]);
  //       // console.log("上报百度统计", fullPath);
  //     }
  //   }

  //   // continue
  //   next();
  // });
};
